//
//  UIButton+Help.swift
//  微博
//
//  Created by hejinyin on 2017/8/30.
//  Copyright © 2017年 WangQiang. All rights reserved.
//

import UIKit
extension UIButton{

    //便利构造函数不创建内存
    convenience init(_ imageName:String,backgroundImageName:String) {
        self.init()
        setImage(UIImage.init(named: imageName), for: .normal)
        setImage(UIImage.init(named: imageName + "_highlighted"), for: .highlighted)
        setBackgroundImage(UIImage.init(named: backgroundImageName), for: .normal)
        setBackgroundImage(UIImage.init(named: backgroundImageName + "_highlighted"), for: .highlighted)
    }
    convenience init(_ title:String , normalColor:UIColor , highlightedColor:UIColor, fontSize:CGFloat = 16 ,backgroundImage:String = ""){
        self.init()
        setTitle(title, for: .normal)
        setTitleColor(normalColor, for: .normal)
        setTitleColor(highlightedColor, for: .highlighted)
        titleLabel?.font = UIFont.systemFont(ofSize: fontSize)
        if backgroundImage.lengthOfBytes(using: .utf8) > 0 {
            setBackgroundImage(UIImage.init(named: backgroundImage), for: .normal)
        }
    }
}
